<?php
class Admin_Model_Monhoc {
	
	private $monhoc;
	
	function __construct(){
		$this->monhoc = new Admin_Model_DbTable_Monhocs();
	}
	
	public function selectCourse($where=null,$order =NULL){
		$dbAdapter = Zend_Db_Table::getDefaultAdapter();
		$dbSelect  = new Zend_Db_Select($dbAdapter);
		
		$dbSelect->from(array('mh'=>'monhoc'),'*');
//				->joinLeft(array('kt'=> 'kiemtra'), 'kt.idMonHoc = mh.id','idKiemTra')
//				->joinLeft(array('ch'=>'cauhoi'), 'ch.idMonHoc = mh.id',array('idCauHoi','dapAnDung'));
		if ($where != NULL) $dbSelect->where($where);
		if($order != NULL)	$dbSelect->order($order);
		
		return $dbSelect;
	}
	public function listMonHoc($where =null){
		if($where != null){
			return $this->monhoc->select()->where($where);
		}else{
			return $this->monhoc->select();
		}
	}
	
	/**
	 * 
	 * Them mon hoc
	 * @param unknown_type $tenMonHoc: ten mon hoc (string)
	 */
	public function addMonHoc($tenMonHoc){
		$data = array(
			'tenMonHoc'		=>	$tenMonHoc
		);
		
		$this->monhoc->insert($data);
	}
	
	/**
	 * 
	 * cap nhap thong tin mon hoc
	 * @param unknown_type $tenMonHoc : ten mon hoc (String)
	 * @param unknown_type $idMon : ma mon hoc (int)
	 */
	public function updateMonHoc($tenMonHoc,$idMon){
		$data = array(
			'tenMonHoc'	=>	$tenMonHoc
		);
		
		$this->monhoc->update($data, 'id ='.$idMon);
	}
	
	public function deleteMonHoc($idMon){
		$this->monhoc->delete('id = '.$idMon);
	}
	
	public function moveTrash($idMon){
		$this->monhoc->update(array('trash' => '1'), 'idMonHoc = '.$idMon);
	}
	
	public function fetchAllMonHoc($where=null){
		if($where != null){
			return $this->monhoc->fetchAll($where);	
		}else{
			return  $this->monhoc->fetchAll();
		}
	}
	
	public function fetchRowMonHoc($id){
		return $this->monhoc->fetchRow('id = '.$id)->toArray();
	}
	
}